//
//  MCEditTableViewController.m
//  MClient
//
//  Created by  史正烨 on 10-9-1.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "MCEditTableViewController.h"
#import "DateTimeSelectView.h"
#import "MClientAppDelegate.h"
#import "MCFunction.h"
#import "MServerDAO.h"
#import "DocFileListDisplayController.h"
#import "FileViewController.h"
#import "MCErrorManagement.h"
#import "MCControl.h"
#import "CASignUntitledViewController.h"
#import "LookupSelectView.h"
#import "RegexKitLite.h"
#import "CustomMoviePlayer.h"

#define eCamera				@"拍摄照片"
#define eVideo				@"录制视频"
#define eGetFromPhoto		@"从图片库选择"
#define eSign				@"手写签名"
#define eViewFile			@"查阅文件"
#define eDeleteFile			@"删除文件"
#define egetFromFileLib		@"从文件库选择"
#define edownloadFile		@"下载文件"

@interface MCEditTableViewController(Private)
- (void) downloadFile;
@end

@implementation MCEditTableViewController

@synthesize fileAttach;
@synthesize dataFrom;
@synthesize fileField;
@synthesize fileData;
@synthesize tempLocation;
@synthesize cacheFile;
@synthesize operateFlag;
@synthesize isTabStyle;
@synthesize isNeedShortcutsToolBar;

- (void)showActionSheetOfFile:(NSMutableDictionary *)field {
	UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"选择操作" 
													  delegate:self 
											 cancelButtonTitle:nil 
										destructiveButtonTitle:nil 
											 otherButtonTitles:nil];
	menu.tag = 1;
	bool video = NO;
	bool camera = NO;
	bool photo = NO;
	bool sign = NO;
	if ([field objectForKey:@"fun"]) {
		NSString *value = [field objectForKey:@"fun"];
		NSString *fieldType = [field objectForKey:@"type"];
		NSArray *functions = [value componentsSeparatedByString:@";"];
		for (NSString *fun in functions) {
			if ([fieldType isEqualToString:@"J"]) {
				if ([@"1" isEqualToString:fun]) {
					video = YES;
					continue;
				}
				if ([@"2" isEqualToString:fun]) {
					camera = YES;
					continue;
				}
				if ([@"3" isEqualToString:fun]) {
					photo = YES;
					continue;
				}
			}
			if ([fieldType isEqualToString:@"S"]) {
				if ([@"1" isEqualToString:fun]) {
					camera = YES;
					continue;
				}
				if ([@"2" isEqualToString:fun]) {
					sign = YES;
					continue;
				}
				if ([@"3" isEqualToString:fun]) {
					photo = YES;
					continue;
				}
			}
		}
	}else {
		video = YES;
		camera = YES;
		photo = YES;
		sign = YES;
	}
	if (camera) {
		[menu addButtonWithTitle:eCamera];
	}
	if (video) {
		[menu addButtonWithTitle:eVideo];
	}
	if (photo) {
		[menu addButtonWithTitle:eGetFromPhoto];
	}
	if (sign) {
		[menu addButtonWithTitle:eSign];
	}
	[self addOtherShowMenu:menu];
	int cancelIndex = [menu addButtonWithTitle:@"取消"];
	menu.cancelButtonIndex = cancelIndex;
	[menu showFromTabBar:(UITabBar *)[self.navigationController view]];
	[menu release];
	return;	
}

- (void)addOtherShowMenu:(UIActionSheet *)menu {
	//[menu addButtonWithTitle:egetFromFileLib];
	if (self.fileField != nil && ![@"" isEqualToString:self.fileField]) {
		[menu addButtonWithTitle:eViewFile];
		//[menu addButtonWithTitle:edownloadFile];
		[menu addButtonWithTitle:eDeleteFile];
	}
}

- (void)selectFilePathActionSheetEvent:(NSInteger)buttonIndex
						   actionSheet:(UIActionSheet *)actionSheet
{
	NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
	if([buttonTitle isEqualToString:eCamera]) {
		if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
			UIImagePickerController *picker = [[UIImagePickerController alloc] init];
			picker.delegate = self;
			picker.sourceType = UIImagePickerControllerSourceTypeCamera;
			picker.mediaTypes =  [NSArray arrayWithObject:@"public.image"];
			[self presentModalViewController:picker animated:YES];
			[picker release];
		} else {
			return;
		}
	}
	else if([buttonTitle isEqualToString:eVideo]) {
		if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
			UIImagePickerController *picker = [[UIImagePickerController alloc] init];
			picker.delegate = self;
			picker.sourceType = UIImagePickerControllerSourceTypeCamera;
			NSArray *temp_MediaTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType];
			if (![temp_MediaTypes containsObject:@"public.movie"]) {
				[self messageBox:@"提示" 
						 message:@"您的手机硬件不支持视频录制功能!" 
						delegate:self
			   cancelButtonTitle:nil
			   otherButtonTitles:@"确定"];
				return;
			}
			picker.mediaTypes =  [NSArray arrayWithObject:@"public.movie"];
			[self presentModalViewController:picker animated:YES];
			[picker release];
		} else {
			return;
		}
	}
	else if ([buttonTitle isEqualToString:eGetFromPhoto]) {
		UIImagePickerController *picker = [[UIImagePickerController alloc] init];
		picker.delegate = self;
		picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
		[self presentModalViewController:picker animated:YES];
		[picker release];
	}
	else if ([buttonTitle isEqualToString:egetFromFileLib]) {
		DocFileListDisplayController *docFileListDisplayController = [[DocFileListDisplayController alloc] init];
		docFileListDisplayController.isMultiFile = NO;
		[self.navigationController pushViewController:docFileListDisplayController animated:YES];
		[docFileListDisplayController release];
	}
	else if ([buttonTitle isEqualToString:eSign]) {
		CASignUntitledViewController* signViewController = [[CASignUntitledViewController alloc] init];
		[self.navigationController pushViewController:signViewController animated:YES];
		[signViewController release];
	}
	else if ([buttonTitle isEqualToString:eViewFile]) {
		[self viewFileContent];
	}
	else if ([buttonTitle isEqualToString:edownloadFile]) {
		[self downloadFile];
	}
	else if ([buttonTitle isEqualToString:eDeleteFile]){
		[self messageBox:@"确定删除?" 
				 message:nil 
				delegate:self
	   cancelButtonTitle:@"取消"
	   otherButtonTitles:@"确定"];
	}else {
		return;
	}
}

- (void)dealloc {
	[fileAttach release];
	[dataFrom release];
	[fileField release];
	[fileData release];
	[tempLocation release];
	[cacheFile release];
	[operateFlag release];
	[super dealloc];
}

#pragma mark ---- 图片事件处理方法 ----
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
   @try {
		NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
		if ([mediaType isEqualToString:@"public.image"]){
			self.cacheFile = [MCFunction getTempFileName:@"jpeg"];
			NSString *imageFile = [NSString stringWithFormat:@"%@%@",NSTemporaryDirectory(),self.cacheFile];
			
			UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
			[UIImageJPEGRepresentation(image, 1.0f) writeToFile:imageFile atomically:YES];
		}
		else if([mediaType isEqualToString:@"public.movie"]){
			self.cacheFile = [MCFunction getTempFileName:@"mov"];
			NSString *videoFile = [NSString stringWithFormat:@"%@%@",NSTemporaryDirectory(),self.cacheFile];
			
			NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
			NSData *videoData = [NSData dataWithContentsOfURL:videoURL];
			[videoData writeToFile:videoFile atomically:YES];
		}
	   [picker dismissModalViewControllerAnimated:YES];
	   [self getUploadFileName];
	   self.fileData = [NSInputStream inputStreamWithFileAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), self.cacheFile]];
	}
	@catch (NSException * e) {
		[[MCErrorManagement instance] doError:@"99" 
								returnMessage:[NSString stringWithFormat:@"main: Caught %@: %@", [e name], [e reason]]];
	}
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
	[picker dismissModalViewControllerAnimated:YES];
}

- (void) getUploadFileName {
	self.operateFlag = @"getUploadFileName";
	[[MServerDAO sharedInstance] getUploadFileNameAsync:self];
}

- (void)getUploadFileNameSuccess:uploadTempLocation {
	self.tempLocation = uploadTempLocation;
	self.operateFlag = @"uploadFile";
	[[MServerDAO sharedInstance] uploadFileAsync:@"upload" 
										location:self.tempLocation 
											data:self.fileData
										delegate:self];	
}
- (void)uploadFileSuccess {
	[self.fileAttach setObject:self.cacheFile forKey:@"fname"];
	[self.fileAttach setObject:self.tempLocation forKey:@"lcn"];
	[self.fileAttach setObject:@"A" forKey:@"opt"];
	self.fileField = self.cacheFile;
	[self messageBox:@"操作成功" 
			 message:@"上传成功!" 
			delegate:nil
   cancelButtonTitle:nil
   otherButtonTitles:@"确定"];
	[self reloadData];
}

- (void)downloadFile {
	if ([self.fileAttach objectForKey:@"opt"]) {
		if ([[self.fileAttach objectForKey:@"opt"] isEqualToString:@"A"]) {
			[self messageBox:@"操作提示" 
					 message:@"文件已在本地文件库中，无需下载！" 
					delegate:self
		   cancelButtonTitle:nil
		   otherButtonTitles:@"确定"];
			return;
		}
	}
	
	NSString *fileName = [self.fileAttach objectForKey:@"fname"];
	if (fileName == nil || [fileName length] == 0)
		return;
	NSString *fileLocation = [self.fileAttach objectForKey:@"lcn"];
	NSString *type = @"";
	
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *cacheFileName = [[paths objectAtIndex:0] stringByAppendingPathComponent:fileName];
	
	NSFileManager *fileManager = [NSFileManager defaultManager];
	[fileManager changeCurrentDirectoryPath:[[paths objectAtIndex:0] stringByExpandingTildeInPath]];
	[fileManager createFileAtPath:fileName contents:nil attributes:nil];
	
	self.operateFlag = @"downloadFile";
	[[MServerDAO sharedInstance] downloadFileAsync:@"download"
										  dataFrom:self.dataFrom
										  location:fileLocation
										  fileName:fileName
											  page:0
											  type:type 
									  saveLocation:cacheFileName 
										  delegate:self];
}


- (void)downloadFileSuccess{
	[self messageBox:@"操作成功" 
			 message:@"下载成功!" 
			delegate:nil
   cancelButtonTitle:nil
   otherButtonTitles:@"确定"];
}

- (void)getServerError: (NSString *)returnCode returnMessage:(NSString *)returnMessage {
	[super getServerError:returnCode returnMessage:returnMessage];
}

- (void) viewFileContent {
	if ([self.fileAttach objectForKey:@"opt"]) {
		if ([[self.fileAttach objectForKey:@"opt"] isEqualToString:@"A"]) {
			NSString *name = [self.fileAttach objectForKey:@"fname"];
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
			NSString *cacheFileName = [[paths objectAtIndex:0] stringByAppendingPathComponent:name];
            
			if ([name hasSuffix:@"mov"]) {
                // Create custom movie player   
                CustomMoviePlayerViewController *moviePlayer = [[[CustomMoviePlayerViewController alloc] initWithPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), name]] autorelease];//huotianjun 从临时文件目录中调出视频显示。
                
                // Show the movie player as modal
                [self presentModalViewController:moviePlayer animated:YES];//huotianjun
                
                // Prep and play the movie
                [moviePlayer readyPlayer];    //huotianjun
				//[self messageBox:@"提示" message:@"视频文件暂不支持播放功能!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定"];
				return;
			}
			FileViewController *fileView = [[FileViewController alloc] init];
			[self.navigationController pushViewController:fileView animated:YES];
			[fileView release];
			
						
			NSFileManager* manager = [NSFileManager defaultManager];
			if (![manager fileExistsAtPath:cacheFileName]) {
				cacheFileName = [NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), name];
				if (![manager fileExistsAtPath:cacheFileName]) {
					return;
				}
			}
			
			/*NSURL *fileUrl = [[NSURL alloc] initFileURLWithPath:cacheFileName];
			NSURLRequest *req = [NSURLRequest requestWithURL:fileUrl];
			[fileUrl release];
			[fileView.webView loadRequest:req];
			fileView.webView.scalesPageToFit =  YES;
			fileView.title = self.cacheFile;
			[fileView release];
			
			NSURL *fileUrl = [[NSURL alloc] initFileURLWithPath:cacheFileName];
			
			NSURLRequest *req = [NSURLRequest requestWithURL:fileUrl];
			
			[fileUrl release];*/
			
			NSURL *fileUrl = [[NSURL alloc] initFileURLWithPath:cacheFileName];
			NSURLRequest *req = [NSURLRequest requestWithURL:fileUrl];
			[fileUrl release];
			//解决图片下载后默认显示远小于原图的问题。
			NSString* szExtension = [[cacheFileName pathExtension] lowercaseString];
			if ([szExtension isEqualToString:@"png"] || [szExtension isEqualToString:@"bmp"] ||
				[szExtension isEqualToString:@"jpg"] || [szExtension isEqualToString:@"jpeg"] ||
				[szExtension isEqualToString:@"gif"] || [szExtension isEqualToString:@"psd"] ||
				[szExtension isEqualToString:@"swf"]) {
				UIImage *image = [UIImage imageWithContentsOfFile:cacheFileName];
				CGSize size = [image size];
				NSString *imageHTML = nil;
				if (size.width <= self.width && size.height <= self.height) {
					NSString *htmlString = @"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>"
					@"<html xmlns='http://www.w3.org/1999/xhtml'>"
					@"<head>"
					@"<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />"
					@"</head>"
					@"<body><img src='%@' width='%f' height='%f'></body>"
					@"</html>";
					imageHTML  = [NSString stringWithFormat:htmlString, fileUrl, size.width, size.height];
				} else if (size.width <= self.width || size.height <= self.height) {
					NSString *htmlString = @"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>"
					@"<html xmlns='http://www.w3.org/1999/xhtml'>"
					@"<head>"
					@"<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />"
					@"<style type='text/css'>.customImg{%@='%f'}</style>"
					@"</head>"
					@"<body><img src='%@' class='customImg'></body>"
					@"</html>";
					imageHTML  = [NSString stringWithFormat:htmlString, ((size.width <= self.width) ? @"width" : @"height"),
								  ((size.width <= self.width) ? size.width : size.height), fileUrl];
				} else if (size.width <= size.height) {
					NSString *htmlString = @"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>"
					@"<html xmlns='http://www.w3.org/1999/xhtml'>"
					@"<head>"
					@"<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />"
					@"<style type='text/css'>.customImg{width='%f'}</style>"
					@"</head>"
					@"<body><img src='%@' class='customImg'></body>"
					@"</html>";
					imageHTML  = [NSString stringWithFormat:htmlString, self.width, fileUrl];
				} else {
					NSString *htmlString = @"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>"
					@"<html xmlns='http://www.w3.org/1999/xhtml'>"
					@"<head>"
					@"<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />"
					@"<style type='text/css'>.customImg{height='%f'}</style>"
					@"</head>"
					@"<body><img src='%@' class='customImg'></body>"
					@"</html>";
					imageHTML  = [NSString stringWithFormat:htmlString, self.height, fileUrl];
				}
				if (imageHTML) {
					MCLog(@"imageHTML=%@", imageHTML);
					fileView.webView.scalesPageToFit = YES;
					[fileView.webView loadHTMLString:imageHTML baseURL:nil];
				}
			} else if ([szExtension isEqualToString:@"html"] || [szExtension isEqualToString:@"htm"]) {
				NSData *htmlData = [NSData dataWithContentsOfFile:cacheFileName];  
				[fileView.webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@"http://iphoneincubator.com"]]; 
				fileView.webView.scalesPageToFit = YES;
			}
			else {
				fileView.webView.scalesPageToFit = YES;
				[fileView.webView loadRequest:req];
			}
			return;
		}
	}
	
	NSString *fileName = [self.fileAttach objectForKey:@"fname"];
	if (fileName == nil || [fileName length] == 0)
		return;
	if ([fileName hasSuffix:@"mov"]) {
		[self messageBox:@"提示" 
				 message:@"视频文件暂不支持播放功能!" 
				delegate:self
	   cancelButtonTitle:nil
	   otherButtonTitles:@"确定"];
		return;
	}
	NSString *fileLocation = [self.fileAttach objectForKey:@"lcn"];
	NSMutableDictionary *fileAttribute = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
										  fileName,@"fileName",
										  fileLocation,@"fileLocation",
										  @"download",@"actionType",
										  self.dataFrom,@"dataFrom",nil];
	FileViewController *fileView = [[FileViewController alloc] init];
	[self.navigationController pushViewController:fileView animated:YES];
	fileView.title = @"文件下载中...";
	fileView.fileAttribute = fileAttribute;
	[fileAttribute release];
	[fileView getDataFromServer];
	[fileView release];
	return;				
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
	if (buttonIndex == 1) {
		[self.fileAttach setObject:@"" forKey:@"fname"];
		[self.fileAttach setObject:@"D" forKey:@"opt"];
		[self reloadData];
		self.fileField = @"";
	}
}

#pragma mark ----输入法键盘上点击完成按钮 ----
- (void) textFieldDone:(id)sender
{
	[sender resignFirstResponder];
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{	
	if ([string isEqualToString:@""] || [string isEqualToString:@"\n"]) {
		return YES;
	}
	NSString* textInput = [textField.text stringByAppendingString:string];
	switch (textField.fieldType) {
		case '6': //百分比
			break;
		case '5': //超级链接
			break;
		case '7': //金额
			break;
		case '9': //电话
			break;
		case 'A': //电子邮件
			break;
		case 'E': //数字
			if ([textInput hasPrefix:@"."] || [textInput hasPrefix:@"00"] ||
				[textInput hasSuffix:@".."] || 
				([textField.text rangeOfString:@"."].length > 0 && [string isEqualToString:@"."])) {
				return NO;
			} else {
				if ([string isMatchedByRegex:@"[0-9.]"]) {
					return YES;
				}
				return NO;
			}
			break;
		case 'F': //文本
			break;
		case 'Q': //手机号码
			break;
		case 'O': //密码
			break;
		case 'N': //验证码
			break;
		case 'B': //复选框
			break;
		case 'Y': //文件（多个）
		case '8': //文本区
		case 'G': //文本区
		case 'T': //手机定位
		case 'J': //文件
			break;
		case '0': //html
			break;
		case 'S': //图片
			break;
		case '3': //主－详细关系
		case '4': //查找关系
		case 'U': //多选过滤
		case 'H': //单选列表（下拉框）
		case 'I': //多选列表（列表框）
		case 'K': //单选列表（单选按钮）
		case 'L': //多选列表（复选框）
		case '1': //公式
		case '2': //自动编号
		case 'C': //日期
		case 'D': //日期时间
		default:
			break;
	}
	return YES;
}

#pragma mark ----键盘出现、消失时的相关处理 ----

// Called when the UIKeyboardWillShowNotification is sent.
- (void)keyboardDidShown:(NSNotification*)aNotification
{	
	@try {
		NSDictionary* info = [aNotification userInfo];
		
		// Get the size of the keyboard.
		NSValue* aValue = [info objectForKey:@"UIKeyboardBoundsUserInfoKey"];
		CGSize keyboardSize = [aValue CGRectValue].size;
		
		CGRect frame = self.tableview.frame;
		frame.size.height = self.height - keyboardSize.height - frame.origin.y + CGRectGetHeight(self.tabBarController.tabBar.frame);
		self.tableview.frame = frame;
		
		MCControl* filed = (MCControl*)[self findFirstResponder];
		if (filed && filed.tagEx > 0) {
			int section = filed.tagEx / 100;
			int row = filed.tagEx % 100;
			NSIndexPath* indexPath = [NSIndexPath indexPathForRow:row inSection:section];
			[self.tableview scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
		}
		
		if ([DateTimeSelectView instance].isShown) {
			[[DateTimeSelectView instance] selectCancelAction];
		}
		if ([LookupSelectView instance].isShown) {
			[[LookupSelectView instance] selectCancelAction];
		}
		
		UITextField* textField = (UITextField*)[self findFirstResponder];
		if (textField.keyboardType == UIKeyboardTypeNumberPad) {
			UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
			UIView* keyboard;
			for(int i=0; i<[tempWindow.subviews count]; i++) {
				keyboard = [tempWindow.subviews objectAtIndex:i];
				if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES ||
				   [[keyboard description] hasPrefix:@"<UIPeripheralHostView"]) {
					UIButton* doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
					if (CGRectGetHeight(self.view.bounds) > CGRectGetWidth(self.view.bounds)) {//竖屏
						doneButton.frame = CGRectMake(0, 163, 106, 53);
					} else {
						doneButton.frame = CGRectMake(0, 120, 158, 41);
					}
					
					doneButton.adjustsImageWhenHighlighted = NO;
					[doneButton setTitle:@"Done" forState:UIControlStateNormal];
					[doneButton setTitle:@"Done" forState:UIControlStateHighlighted];
					[doneButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
					[doneButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
					[doneButton addTarget:self action:@selector(doneButton) forControlEvents:UIControlEventTouchUpInside];
					
					[keyboard addSubview:doneButton];
				}
			}
		}
	}
	@catch (NSException * e) {
		[[MCErrorManagement instance] doError:@"100" returnMessage:[e reason]];
	}
}


// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardDidHidden:(NSNotification*)aNotification
{
	self.tableview.frame = CGRectMake(0, 0, self.width, self.height);
}
@end
